/******************************************************************************
 * Copyright (C) 2024 Createtree, Inc.(Gmbh) or its affiliates.
 *
 * All Rights Reserved.
 *
 * @file bsp_led_driver.h
 *
 * @par dependencies
 * - stdio.h
 * - stdint.h
 *
 * @author Createtree | R&D Dept. | liuzhihuawy@163.com
 *
 * @brief Provide the HAL APIs of LED and corresponding opetions.
 *
 * Processing flow:
 *
 * call directly.
 *
 * @version V1.0 2024-10-24
 *
 * @note 1 tab == 4 spaces!
 *
 *****************************************************************************/
#ifndef __BSP_LED_DRIVER_H__ // Avoid repeated including same files later
#define __BSP_LED_DRIVER_H__
//******************************** Includes *********************************//
#include <stdint.h>
#include <stdio.h>

//******************************** Includes *********************************//

//******************************** Defines **********************************//
#define DEBUG                     /* Debug mode                              */
#define USING_LED_ASSERT          /* Use parameter assert                    */
#define OS_SUPPORTING             /* OS is supported                         */
#define LED_DRIVER_INITED       1 /* LED is inited                           */
#define LED_DRIVER_NOT_INITED   0 /* LED is not inited                       */

typedef struct bsp_led_driver bsp_led_driver_t;

typedef enum
{
    LED_STATUS_OK       = 0,     /* LED operation is successful              */
    LED_STATUS_ERROR    = 1,     /* LED operation is failed                  */
    LED_STATUS_INITED   = 2,     /* LED is inited                            */
    LED_SATUS_RESERVED  = 0xFF,  /* Reserved                                 */
} led_status_t;

typedef enum 
{
    LED_DUTY_CYCLE_MIN = 0,     /* Turn off the LED                          */
    LED_DUTY_CYCLE_0   = 0,     /* Turn off the LED                          */
    LED_DUTY_CYCLE_10  = 10,    /* Turn on the LED for 10% of the time       */
    LED_DUTY_CYCLE_25  = 25,    /* Turn on the LED for 25% of the time       */
    LED_DUTY_CYCLE_50  = 50,    /* Turn on the LED for 50% of the time       */
    LED_DUTY_CYCLE_75  = 75,    /* Turn on the LED for 75% of the time       */
    LED_DUTY_CYCLE_100 = 100,   /* Turn on the LED for 100% of the time      */
    LED_DUTY_CYCLE_MAX = 100,   /* Turn on the LED for 100% of the time      */
} led_duty_cycle_t; /* LED duty cycle */


typedef struct 
{
    led_status_t (*pf_led_on)(void);
    led_status_t (*pf_led_off)(void);
} led_operations_t;

typedef struct
{
    led_status_t (*pf_get_time)(uint32_t * const ms);
} time_base_t;

#ifdef OS_SUPPORTING
typedef struct
{
    led_status_t (*pf_sleep)(const uint32_t ms);
} os_sleep_t;
#endif /* OS_SUPPORTING */

typedef led_status_t (*pf_led_ctrl_t)
                     (bsp_led_driver_t *self,
                      const uint16_t period,             /* ms    */
                      const uint8_t blink_times,         /* times */
                      const led_duty_cycle_t duty_cycle);


struct bsp_led_driver
{
    /************** Private variable **************/
    uint8_t                               is_inited;
    uint16_t                              period_ms;
    uint8_t                             blink_times;
    led_duty_cycle_t                     duty_cycle;

    /******** External provided interfaces ********/
    const led_operations_t         *p_led_opes_inst;
    const time_base_t                  *p_time_base;
#ifdef OS_SUPPORTING
    const os_sleep_t                    *p_os_sleep;
#endif /* OS_SUPPORTING */
    /******************** APIs ********************/
    pf_led_ctrl_t                       pf_led_ctrl;
    
};

//******************************** Defines **********************************//

//******************************** Declaring ********************************//


/**
 * @brief led constructor function
 * @param self led driver instance
 * @param hled_opes led operations instance
 * @param hos_sleep os sleep instance
 * @param htime_base time base instance
 * @retval led_status_t status of the operation
 * @note This function is used to initialize the led driver
 *  steps:
 *  1. Check the input parameters
 *  2. Check if the led driver is already initialized
 *  3. Add the interfaces to the led driver instance
 *  4. Initialize the led driver
 * @date 2024-10-25
 */
led_status_t bsp_led_constructor(
                                          bsp_led_driver_t * const        self,
                                    const led_operations_t * const   hled_opes,
#ifdef OS_SUPPORTING
                                    const os_sleep_t       * const   hos_sleep,
#endif /* OS_SUPPORTING */
                                    const time_base_t      * const htime_base);

//******************************** Declaring ********************************//

#endif /* __BSP_LED_DRIVER_H__ */
